home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / graph_pl.exe / DEMO.C < prev    next >
C/C++ Source or Header  |  1992-02-05  |  8KB  |  207 lines

  1. /*
  2.       ******************************************************************
  3.       **                                                               *
  4.       **   THAT MATERIAL CONTAINED HEREIN WHICH  WAS SUPPLIED BY PAUL  *
  5.       **   LAPSANSKY IS PROPRIETARY TO  PAUL LAPSANSKY  AND IS NOT TO  *
  6.       **   BE REPRODUCED, USED OR DISCLOSED EXCEPT IN ACCORDANCE WITH  *
  7.       **   PROGRAM LICENSE OR UPPON WRITTEN AUTHORIZATION OF:          *
  8.       **                                                               *
  9.       **                 PAUL LAPSANSKY                                *
  10.       **                 1905 BEECH ST. APT. 317                       *
  11.       **                 VALPARAISO, INDIANA 46383                     *
  12.       **                                                               *
  13.       **                 GENIE:                                        *
  14.       **                    P.LAPSANSKY                                *
  15.       **                                                               *
  16.       ******************************************************************
  17.  
  18.        PROGRAM-ID.   DEMO.C
  19.        AUTHOR.       PAUL LAPSANSKY
  20.        DATE-WRITTEN. FEBRUARY 5, 1992
  21.  
  22.       ******************************************************************
  23.       **                                                               *
  24.       **   TITLE:  DEMO PROGRAM FOR GRAPHS LIBRARY                     *
  25.       **                                                               *
  26.       **   PROGRAM DESCRIPTION:                                        *
  27.       **                                                               *
  28.       **       This program is a working demo of the graph functions   *
  29.       **       bargraph, bargraph3d, and piechart.  This program       *
  30.       **       requires Turbo C version 1.5 or higher, Turbo C++ or    *
  31.       **       Borland C++.  This program must be linked with the      *
  32.       **       graphs library GRAPH_C.LIB.  The BGI and FONT files     *
  33.       **       must reside in the same directory as the compiler or    *
  34.       **       linked with the program.                                *
  35.       **                                                               *
  36.       ******************************************************************
  37.  
  38.       ******************************************************************
  39.       **                                                               *
  40.       **   MAINTENANCE HISTORY:                                        *
  41.       **                                                               *
  42.       **     DATE   REVISED BY      VER #    DESCRIPTION               *
  43.       **                                                               *
  44.       **   02/05/92 PAUL LAPSANSKY   1.00    ORIGINAL CODE.            *
  45.       **                                                               *
  46.       ******************************************************************
  47.  
  48.       ******************************************************************
  49.       **                                                               *
  50.       **   COMPILER-OPTIONS:                                           *
  51.       **                                                               *
  52.       **     MEMORY-MODEL:              COMPACT                        *
  53.       **                                                               *
  54.       **     FLOATING-POINT:            ON                             *
  55.       **                                                               *
  56.       ******************************************************************
  57. */
  58.  
  59. #include <graphics.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62.  
  63. #define AUTO 0
  64.  
  65. main()
  66. {
  67.    int driver;        /* display driver */
  68.    int num_pts;       /* number of data points */
  69.    int font;          /* text font */
  70.    int pattern;       /* graph fill pattern */
  71.    int color;         /* graph fill color */
  72.    int size;          /* text size */
  73.    int gr_return;     /* error code returned by graph functions */
  74.  
  75.    float max;         /* largest data value */
  76.  
  77.    float data[12]={10,20,3,4.5,15,7,1,15,8,5.9,11,3};  /* data values */
  78.  
  79.    char x_label[20];  /* x-axis label */
  80.    char y_label[20];  /* y-axis label */
  81.    char title[20];    /* graph title */
  82.    char footnote[40]; /* pie chart footnote */
  83.  
  84.    char values[12][10]={"JAN","FEB","MAR","APR","MAY","JUN",
  85.                         "JUL","AUG","SEP","OCT","NOV","DEC"};
  86.  
  87.    /* display bargraph */
  88.  
  89.    driver=DETECT;      /* detect display adapter */
  90.    num_pts=12;
  91.    font=TRIPLEX_FONT;
  92.    pattern=SOLID_FILL;
  93.    color=GREEN;
  94.    size=2;             /* reduce x-axis values */        
  95.    max=AUTO;           /* determine largest data value and auto scale graph */
  96.    strcpy(x_label,"X-AXIS");
  97.    strcpy(y_label,"Y-AXIS");
  98.    strcpy(title,"BARGRAPH DEMO");
  99.    
  100.    gr_return=bargraph(driver,num_pts,data,max,font,pattern,
  101.                       color,x_label,y_label,title,values,size);
  102.  
  103.    gr_error(gr_return);
  104.    getch();                 
  105.                                 
  106.    /* display 3D bargraph */
  107.    
  108.    color=BROWN;
  109.    strcpy(title,"3D BARGRAPH DEMO");
  110.  
  111.    gr_return=bargraph3d(driver,num_pts,data,max,font,pattern,
  112.                        color,x_label,y_label,title,values,size);
  113.  
  114.    gr_error(gr_return);
  115.    getch();
  116.  
  117.    /* display piechart */
  118.  
  119.    strcpy(title,"PIE-CHART DEMO");
  120.    strcpy(footnote,"Footnote goes here!");
  121.  
  122.    gr_return=piechart(driver,num_pts,data,pattern,font,
  123.                       title,footnote,values,size);
  124.  
  125.    gr_error(gr_return);
  126.    getch();
  127.  
  128.    restorecrtmode();    /* restore previous display and memory */
  129.    exit(0);
  130.  
  131. }
  132.  
  133. gr_error(gr_return)   
  134.    
  135.    int gr_return;
  136. {
  137.    switch(gr_return) {
  138.      case grOk:          /* successful */        
  139.      break;
  140.      case grNoInitGraph:  
  141.        printf("\n%s\n","No driver installed");
  142.        exit(0);
  143.      break;
  144.      case grNotDetected:
  145.        printf("\n%s\n","No graphics hardware in system");
  146.        exit(0);
  147.      break;
  148.      case grFileNotFound:
  149.        printf("\n%s\n","Driver file not found");
  150.        exit(0);
  151.      break;
  152.      case grInvalidDriver:
  153.        printf("\n%s\n","Invalid driver file");
  154.        exit(0);
  155.      break;
  156.      case grNoLoadMem:
  157.        printf("\n%s\n","Not enough memory");
  158.        exit(0);
  159.      break;
  160.      case grNoScanMem:
  161.        printf("\n%s\n","Insufficient memory for scan fill");
  162.        exit(0);
  163.      break;
  164.      case grNoFloodMem:
  165.        printf("\n%s\n","Insufficient memory for flood fill");
  166.        exit(0);
  167.      break;
  168.      case grFontNotFound:
  169.        printf("\n%s\n","Font file not found");
  170.        exit(0);
  171.      break;
  172.      case grNoFontMem:
  173.        printf("\n%s\n","Insufficient memory for font");
  174.        exit(0);
  175.      break;
  176.      case grInvalidMode:
  177.        printf("\n%s\n","Invalid mode");
  178.        exit(0);
  179.      break;
  180.      case grError:
  181.        printf("\n%s\n","General graphics error");
  182.        exit(0);
  183.      break;
  184.      case grIOerror:
  185.        printf("\n%s\n","I/O error");
  186.        exit(0);
  187.      break;
  188.      case grInvalidFont:
  189.        printf("\n%s\n","Invalid font file");
  190.        exit(0);
  191.      break;
  192.      case grInvalidFontNum:
  193.        printf("\n%s\n","Invalid font number");
  194.        exit(0);
  195.      case -18: /* not available on all versions of Turbo C */
  196.        printf("%s\n","Incorrect driver version"); 
  197.        exit(0);
  198.      break;
  199.      case -25: 
  200.        printf("\n%s\n","Too many data points");
  201.        exit(0);
  202.      default:
  203.        printf("\n%s\n","Undetectable error");
  204.        printf("%d",gr_return);
  205.        exit(0);
  206.    }
  207. }